#!/bin/sh
#
# Copyright (C) 2000-2022 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#

#
# Run a simple backup of the /lib directory
#   then restore it.
#
cwd=`pwd`
. scripts/functions
scripts/cleanup
scripts/cleanup-tape
scripts/copy-tape-confs
echo "/lib" >${cwd}/tmp/file-list
echo " "
echo " "
echo " === Starting lib-tape-root test ==="
echo " "
echo " "

cat <<END_OF_DATA > >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
label storage=tape Volume=TestVolume001 slot=0
run job=NightlySave yes
wait
messages
@# 
@# now do a restore
@#
@$out ${cwd}/tmp/log2.out
restore where=${cwd}/tmp/bacula-restores select all done
yes
wait
messages
quit
END_OF_DATA

run_bacula
stop_bacula

cd /
${cwd}/bin/testls -e ${cwd}/scripts/exclude-usr-test lib >${cwd}/tmp/original
cd ${cwd}/tmp/bacula-restores
${cwd}/bin/testls -e ${cwd}/scripts/exclude-usr-test lib >${cwd}/tmp/restored
cd ${cwd}/tmp
sed s%.*lib/kbd/consolefonts$%lib/kbd/consolefonts% original >1
sort <1 >original
#
sed s%.*lib/kbd/consolefonts$%lib/kbd/consolefonts% restored >1
sort <1 >restored
rm -f 1
#
cd ${cwd}
diff ${cwd}/tmp/original ${cwd}/tmp/restored 2>&1 1>/dev/nul
if [ $? != 0 ] ; then
   echo " "
   echo " "
   echo "  ===== lib-tape-root failed!!! ===== "
   echo "  ===== lib-tape-root failed!!! ===== " >>test.out
   echo " "
else
   echo "  ===== lib-tape-root OK ===== "
   echo "  ===== lib-tape-root OK ===== " >>test.out
   scripts/cleanup
fi
